package com.lagou;

import com.lagou.client.RPCConsumer;
import com.lagou.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;

@SpringBootApplication(scanBasePackages = {"com.lagou"})
public class ConsumerBoot {
@Autowired
private RPCConsumer rpcConsumer;


    //参数定义
    private static final String PROVIDER_NAME = "UserService#sayHello#";

    public static void main(String[] args){
        SpringApplication app = new SpringApplication(ConsumerBoot.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);
        System.out.println("[客户端]启动成功！");

    }

    @PostConstruct
    void start() throws InterruptedException {
        //1.创建代理对象
        IUserService service = (IUserService) rpcConsumer.createProxy(IUserService.class);

        //2.循环给服务器写数据
        while (true){


            String result = service.sayHello("are you ok !!");
            System.out.println("获取服务端返回结果:"+result);
            Thread.sleep(1000);
        }
    }
}
